Skip to content

docs: Add sample code - #91

Draft
mwien wants to merge 9 commits into
mainfrom
add-sample-code
Draft

docs: Add sample code#91
mwien wants to merge 9 commits into
mainfrom
add-sample-code

Conversation

@mwien

@mwien mwien commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

This PR adds example code that showcases usage of the SDK by exposing HTTP endpoints via a FastAPI application. Similar sample code exists for the other two AI SDKs.

This is a draft PR. The architecture/integration of the sample code may be up to discussion and more features should be added.

Currently, examples are included for the following services:

  • configurations/deployments via the core package
  • native clients (OpenAI/Google/Amazon)
  • orchestration

The following additions are planned:

  • LangChain
  • Grounding
  • Prompt Registry
  • RPT Models

Open things/questions up for discussion:

  • Should the sample_code package be part of the root workspace? This is how it is currently proposed. It would be useful for using it for end-to-end smoke tests.
  • I had to add a pyrightconfig.json to the sample code repo for Pyright to find the base, core and gen packages. Maybe there are better solutions.
  • Currently, each example is completely self-contained (to make it easy to understand and try out for beginners). However, therefore a new OrchestrationService client is created for each orchestration request. How should the correct cleanup look like (for example with regard to the close_http_connection method, which only closes the sync client)?
  • There are some minor type errors from the type checker that one could look into.

@mwien
mwien requested a review from ZhongpinWang August 25, 2026 13:48
Comment thread sample-code/src/sample_code/__init__.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q/req] Why is the path sample-code/src/sample_code? And underscore is preferred to better align with the naming conventions used by other folders.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the standard modern path convention in Python (src layout). In this case, the flat layout should also work fine and is better/more aligned with the rest. I'll switch to that.

Regarding hyphenation: it's aligned in this regard that the low level folder names (which contains the source files) use underscores and only the outermost folder (with the project name) is hyphenated (like ai-sdk-python).

But we can also use sample_code/sample_code/example.py if that's preferred.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See 04ac9e7

@ZhongpinWang ZhongpinWang Aug 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe examples/sample_code/...? Similar to https://github.com/pallets/flask/tree/main/examples

There can be later examples/tutorial/..., examples/langchain_agent/...

Also we never release these packages, should we remove the license file in the folder?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the license file.

In your flask example there is one more layer of indirection: examples/javascript/js_example

For us we currently have: sample-code/sample_code where the outer dir contains already pyproject.toml like the javascript folder in flask.

So we could have examples/sample-code/sample_code... but I guess you still would want to change the name of the middle folder?

Comment thread sample-code/Makefile Outdated
@mwien

mwien commented Aug 27, 2026

Copy link
Copy Markdown
Contributor Author

Another thing to note: I'm currently using a .env file for config that's supposed to lie in the sample-code folder. We could also use a .env file in the repo root...

@ZhongpinWang

Copy link
Copy Markdown
Contributor

Another thing to note: I'm currently using a .env file for config that's supposed to lie in the sample-code folder. We could also use a .env file in the repo root...

Probably I missed it since I am a python sdk newbie. But why is there a .env already at repo root? In JS and Java, we just put .env in sample code and smoke test packages only as these are the only apps that need the credential?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants